import {request} from "./http-base";
import * as api from "../apis";

/**
 * 健康数据也是从这个接口获得
 */
export const getUserProfileDataToday = async () => {
  return request(api.todayProfile)
}
export const updateSteps = async (steps: {
  "calorie": number,
  "distance": number,
  "stepCount": number
}) => {
  return request(api.updateProfile, {
    "bodyProfile": {
      "steps": steps
    }
  }, "PUT")
}
/**
 * 更新血压数据
 * @param bloodPressure
 */
export const updateBloodPressure = async (bloodPressure: { "systolicPressure": number, "diastolicPressure": number, "measurementDate": number}
) => {
  return request(api.updateProfile, {
    "bodyProfile": {
      "bloodPressures": [bloodPressure],
    }
  }, "PUT")
}

/**
 * 更新肾功能数据
 * @param data
 */
export const updateRenal = async (data: { "niaosuan": number, "niaoweiliangdanbai": number, }
) => {
  return request(api.updateProfile, {
    "bodyProfile": {
      "renal": data,
    }
  }, "PUT")
}

/**
 * 更新体重数据
 * @param data
 */
export const updateWeight = async (data: {
                                     "bmi": number,
                                     "bone": number,
                                     "muscle": number,
                                     "pbf": number,
                                     "water": number,
                                     "weight": number
                                   }
) => {
  return request(api.updateProfile, {
    "bodyProfile": {
      "weightInfo": data,
    }
  }, "PUT")
}

/**
 * 更新心率数据
 * @param data
 */
export const updateHeartRate = async (data: { "fastHeartRate": number, "heartRate": number, "restingHeartRate": number, "slowHeartRate": number }
) => {
  return request(api.updateProfile, {
    "bodyProfile": {
      "heartRate": data,
    }
  }, "PUT")
}

/**
 * 更新血糖数据
 * @param data
 */
export const updateBloodSugars = async (data: { "glucoseConcentration": number, "measurementDate": number,"mealPeriod":number}) => {
  return request(api.updateProfile, {
    "bodyProfile": {
      "bloodSugars": [data],
    }
  }, "PUT")
}

/**
 * 更新血脂数据
 * @param data
 */
export const updateXueZhi = async (data: { danguchun: number, dimiduzhidanbai: number, ganyousanzhi: number, gaomiduzhidanbai: number, }
) => {
  return request(api.updateProfile, {
    "bodyProfile": {
      "bloodFat": data,
    }
  }, "PUT")
}

/**
 * 更新睡眠数据
 * @param data
 */
export const updateSleep = async (data: { startTime?:number,wakeUpTime?:number }
) => {
  return request(api.updateProfile, {
    "bodyProfile": {
      "sleep": data,
    }
  }, "PUT")
}
/**
 * 获取用户健康历史数据
 */
type healthType =
  "BLOOD_FAT"
  | "BLOOD_PRESSURE"
  | "BLOOD_SUGAR"
  | "CALORIE"
  | "HEART_RATE"
  | "HEIGHT"
  | "RENAL"
  | "SLEEP"
  | "STEPS"
  | "WEIGHT";
export const getHistoryData = async (dateType: "DAY_OF_MONTH" | "DAY_OF_WEEK", type: healthType) => {
  const response = await request(`${api.historyHealthData}?dateType=${dateType}&healthDataType=${type}`);
  return response.data.data;
}
